package com.ml.mall.api.variant;

import com.ml.mall.annotations.OperLog;
import com.ml.mall.api.BaseController;
import com.ml.mall.bean.base.ApiRestResult;
import com.ml.mall.bean.req.variant.*;
import com.ml.mall.consts.PermissionConst;
import com.ml.mall.service.variant.SysProductVariantRecommendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
* <p>
*  前端控制器
* </p>
*
* @author kyyang
* Created 2021-05-15
*/

@Api(tags = "【product】产品推荐实体")
@RestController
@RequestMapping("/variant_recommend")
public class SysProductVariantRecommendController extends BaseController {

    @Autowired
    private SysProductVariantRecommendService sysProductVariantRecommendService;


    @RequestMapping(method = RequestMethod.POST, path = "/new")
    @OperLog(operDesc = "产品创建", operModul = "variant_recommend", operType = "new")
    @ApiOperation("创建推荐变体")
//    @RequiresPermissions(PermissionConst.PRODUCT_RECOMMEND_NEW)
    public ApiRestResult newVariantRecommend(@RequestBody @Valid VariantRecommendNewReq req) {
        return ApiRestResult.ok( sysProductVariantRecommendService.variantRecommendNew(req));
    }


    @RequestMapping(method = RequestMethod.POST, path = "/del")
    @OperLog(operDesc = "产品删除", operModul = "variant_recommend", operType = "del")
    @ApiOperation("删除推荐变体")
//    @RequiresPermissions(PermissionConst.PRODUCT_RECOMMEND_DEL)
    public ApiRestResult delVariantRecommend(@RequestBody @Valid VariantRecommendDelReq req) {
        return ApiRestResult.ok( sysProductVariantRecommendService.variantRecommendDel(req));
    }


    @RequestMapping(method = RequestMethod.POST, path = "/edit")
    @OperLog(operDesc = "推荐产品编辑", operModul = "variant_recommend", operType = "edit")
    @ApiOperation("推荐产品编辑")
//    @RequiresPermissions(PermissionConst.PRODUCT_RECOMMEND_EDIT)
    public ApiRestResult editVariantRecommend(@Valid @RequestBody VariantRecommendEditReq req ) {
        return ApiRestResult.ok( sysProductVariantRecommendService.variantRecommendEdit(req) );
    }


    @RequestMapping(method = RequestMethod.POST, path = "/query_all")
    @ApiOperation("查询对应类型的推荐产品")
//    @RequiresPermissions(PermissionConst.PRODUCT_RECOMMEND_QUERY_ALL)
    public ApiRestResult queryAllVariantRecommend(@Valid @RequestBody VariantRecommendQueryReq req ) {
        return ApiRestResult.ok(sysProductVariantRecommendService.variantRecommendQueryAll(req));
    }

}
